// method
package main

import (
	"fmt"
	"runtime"
	"time"
)

type TwoInts struct {
	a int
	b int
}

func (tn *TwoInts) AddThem() int {
	return tn.a + tn.b
}

func (tn *TwoInts) AddToParam(param int) int {
	return tn.a + tn.b + param
}

type myTime struct {
	time.Time
}

func (t myTime) first3Chars() string {
	return t.Time.Format("2006-01-02")[:3]
}

func main() {
	tn := new(TwoInts)
	tn.a = 5
	tn.b = 7
	fmt.Println(tn.AddThem())
	fmt.Println(tn.AddToParam(10))
	tn2 := TwoInts{5, 7}
	fmt.Println(tn2.AddThem())

	m := myTime{time.Now()}
	fmt.Println("Full time now", m.String)
	//调用方法
	fmt.Println("First 3 chars", m.first3Chars())

	//垃圾回收
	var m runtime.MemStats
	runtime.ReadMemStats(&m)
	fmt.Printf("%d KB\n", m.Alloc/1024)

}
